package Models;

import java.util.ArrayList;
import java.util.List;

public enum Units {
	OTHER(0),
	EA(1),
	VOL_ML(2),
	VOL_L(3),
	VOL_OZ(4),
	VOL_GAL(5),
    VOL_BBL(6),
	MASS_UG(7),
	MASS_G(8),
	MASS_KG(9),
    MASS_OZ(10),
    MASS_LBS(11);

	private int unit;

	Units(final int unit) {
		this.unit = unit;
	}

	public int getUnit() {
		return unit;
	}

	public static Units getUnit(final String unit) {
		return getUnit(Integer.parseInt(unit));
	}

	public static Units getUnit(final int unit) {

		switch (unit) {
        case 0:
             return OTHER;
        case 1:
            return EA;
		case 2:
			return VOL_ML;
		case 3:
			return VOL_L;
		case 4:
			return VOL_OZ;
		case 5:
			return VOL_GAL;
        case 6:
            return VOL_BBL;
		case 7:
			return MASS_UG;
		case 8:
			return MASS_G;
		case 9:
			return MASS_KG;
        case 10:
            return MASS_OZ;
        case 11:
            return MASS_LBS;
		default:
			throw new EnumConstantNotPresentException(Units.class, String.valueOf(unit));
		}
	}
        
        public static String getUnitLongDescription(final int unit) {
		switch (unit) {
        case 0:
            return "Other";
        case 1:
            return "Each";
        case 2:
			return "Milliliters";
		case 3:
			return "Liters";
		case 4:
			return "Fluid Ounces";
		case 5:
			return "Gallons";
        case 6:
            return "Barrels";
		case 7:
			return "Micrograms";
		case 8:
			return "Grams";
		case 9:
			return "Kilograms";
        case 10:
            return "Ounces";
        case 11:
            return "Pounds";
		default:
			throw new EnumConstantNotPresentException(Units.class, String.valueOf(unit));
		}
	}
        
        public static int getUnitFromShortDescription(final String desc){
            if(desc.equals("mL")){
                return 2;
            } else if(desc.equals("ea")){
            	return 1;
            } else if(desc.equals("L")){
            	return 3;
            } else if(desc.equals("Fl Oz.")){
            	return 4;
            } else if(desc.equals("Gal.")){
            	return 5;
            } else if(desc.equals("BBL")){
            	return 6;
            } else if(desc.equals("ug")){
            	return 7;
            } else if(desc.equals("g")){
            	return 8;
            } else if(desc.equals("kg")){
            	return 9;
            } else if(desc.equals("Oz.")){
            	return 10;
            } else if(desc.equals("Lbs.")){
            	return 11;
            } else {
                return 0;
            }
        }
        
        public static List<String> getComboBoxData(){
            List<String> combo = new ArrayList<String>();
            combo.add("Other");
            combo.add("ea");
            combo.add("mL");
            combo.add("L");
            combo.add("Fl Oz.");
            combo.add("Gal.");
            combo.add("BBL");
            combo.add("ug");
            combo.add("g");
            combo.add("kg");
            combo.add("Oz.");
            combo.add("Lbs.");
            return combo;
        }
        
        public static int getUnitFromLongDescription(final String desc){
            if(desc.equals("Each")){
            	return 1;
            } else if(desc.equals("Milliliters")){
                return 2;
            } else if(desc.equals("Liters")){
            	return 3;
            } else if(desc.equals("Fluid Ounces")){
            	return 4;
            } else if(desc.equals("Gallons")){
            	return 5;
            } else if(desc.equals("Barrels")){
            	return 6;
            } else if(desc.equals("Micrograms")){
            	return 7;
            } else if(desc.equals("Grams")){
            	return 8;
            } else if(desc.equals("Kilograms")){
            	return 9;
            } else if(desc.equals("Ounces")){
            	return 10;
            } else if(desc.equals("Pounds")){
            	return 11;
            } else {
                return 0;
            }
        }
        
        public static String getUnitShortDescription(final int unit) {
		switch (unit) {
        case 0:
            return "Other";
        case 1:
            return "ea";
        case 2:
			return "mL";
		case 3:
			return "L";
		case 4:
			return "Fl Oz.";
		case 5:
			return "Gal.";
        case 6:
            return "BBL";
		case 7:
			return "ug";
		case 8:
			return "g";
		case 9:
			return "kg";
        case 10:
            return "Oz.";
        case 11:
            return "Lbs.";
		default:
			throw new EnumConstantNotPresentException(Units.class, String.valueOf(unit));
		}
	}
        
       /* public static float convertUnits(final int from, final int to, final float amt){
            switch (from) {
                case 0:
                    //Other
                case 10:
                    //mL
                    switch(to){
                        case 15:
                            //L
                            return (float)(amt * 0.001);
                        case 20:
                            //Fl Oz.
                            return (float)(amt * 0.033814);
                        case 25:
                            //Gal
                            return (float)(amt * 0.000264172);
                        case 30:
                            //BBL
                            return (float)(amt * 0.000264172 / 31);
                        default:
                            return (float)(amt);
                    }
                case 15:
                    //L
                    switch(to){
                        case 10:
                            //mL
                            return (float)(amt * 1000);
                        case 20:
                            //Fl Oz.
                            return (float)(amt * 33.814);
                        case 25:
                            //Gal
                            return (float)(amt * 0.264172);
                        case 30:
                            //BBL
                            return (float)(amt * 0.264172 / 31);
                        default:
                            return (float)(amt);
                    }
				case 20:
                    //Fl Oz.
                    switch(to){
                        case 10:
                            //mL
                            return (float)(amt * 29.5735);
                        case 15:
                            //L
                            return (float)(amt * 0.0295735);
                        case 25:
                            //Gal
                            return (float)(amt * 0.0078125);
                        case 30:
                            //BBL
                            return (float)(amt * 0.0078125 / 31);
                        default:
                            return (float)(amt);
                    }
				case 25:
                    //Gal
                    switch(to){
                        case 10:
                            //mL
                            return (float)(amt * 3785.41);
                        case 15:
                            //L
                            return (float)(amt * 3.78541);
                        case 20:
                            //Fl Oz.
                            return (float)(amt * 128);
                        case 30:
                            //BBL
                            return (float)(amt / 31);
                        default:
                            return (float)(amt);
                    }
                case 30:
                    //BBL
                    switch(to){
                        case 10:
                            //mL
                            return (float)(amt * 31 * 3785.41);
                        case 15:
                            //L
                            return (float)(amt * 31 * 3.78541);
                        case 20:
                            //Fl Oz.
                            return (float)(amt * 31 * 128);
                        case 25:
                            //GAL
                            return (float)(amt * 31);
                        default:
                            return (float)(amt);
                    }
                /* Dry Weight Units Next*/
                /*case 100:
                    //ug
                    switch(to){
                        case 105:
                            //g
                            return (float)(amt * .000001);
                        case 110:
                            //kg
                            return (float)(amt * .000000001);
                        case 115:
                            //Oz.
                            return (float)(amt * .000000035274);
                        case 120:
                            //Lbs
                            return (float)(amt * .0000000022046);
                        default:
                            return (float)(amt);
                    }
				case 105:
                    //g
                    switch(to){
                        case 100:
                            //ug
                            return (float)(amt * 1000000);
                        case 110:
                            //kg
                            return (float)(amt * .001);
                        case 115:
                            //Oz.
                            return (float)(amt * 0.035274);
                        case 120:
                            //Lbs
                            return (float)(amt * 0.00220462);
                        default:
                            return (float)(amt);
                    }
				case 110:
                    //kg
                    switch(to){
                        case 100:
                            //ug
                            return (float)(amt * 1000000000);
                        case 105:
                            //g
                            return (float)(amt * 1000);
                        case 115:
                            //Oz.
                            return (float)(amt * 35.274);
                        case 120:
                            //Lbs
                            return (float)(amt * 2.20462);
                        default:
                            return (float)(amt);
                    }
                case 115:
                    //oz
                    switch(to){
                        case 100:
                            //ug
                            return (float)(amt * 28350000);
                        case 105:
                            //g
                            return (float)(amt * 28.3495);
                        case 110:
                            //kg.
                            return (float)(amt * 0.0283495);
                        case 120:
                            //Lbs
                            return (float)(amt * 0.0625);
                        default:
                            return (float)(amt);
                    }
                case 120:
                    //lbs
                    switch(to){
                        case 100:
                            //ug
                            return (float)(amt * 453600000);
                        case 105:
                            //g
                            return (float)(amt * 453.592);
                        case 110:
                            //kg.
                            return (float)(amt * 0.453592);
                        case 115:
                            //Oz
                            return (float)(amt * 16);
                        default:
                            return (float)(amt);
                    }
                default:
                    return 0;
            	}
        }*/
}
